package com.aliwo.design.patterns.simpleFactory;

/**
 * @author xuyayuan
 * @description 生产电视机工厂 角色
 * @date 2021/9/8 10:03
 */
public class TVFactory {

    public static TV produceTV(String brand) {
        if (brand.equalsIgnoreCase("HaiEr")) {
            System.out.println("电视机工厂生产海尔电视机");
            return new HaiErProduct();
        } else if (brand.equalsIgnoreCase("HaiXin")) {
            System.out.println("电视机工厂生产海信电视机");
            return new HaiXinProduct();
        } else if (brand.equalsIgnoreCase("XiaoMi")) {
            System.out.println("电视机工厂生产小米电视机");
            return new XiaoMiProduct();
        } else {
            throw new RuntimeException("没有生产该品牌的电视机");
        }
    }

    public static TV produceTV(Class<? extends TV> clazz) throws InstantiationException, IllegalAccessException {
        if (null == clazz) {
            return null;
        }
        return clazz.newInstance();
    }
}
